package com.codeczx.mygeeknews.zhihu;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.codeczx.mygeeknews.DailyListBean;
import com.codeczx.mygeeknews.DailyListBean.StoriesBean;
import com.codeczx.mygeeknews.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by win10 on 2017/7/2.
 */

public class ZhihuDailyAdapter extends RecyclerView.Adapter<ZhihuDailyAdapter.MyViewHolder> {


    private List<StoriesBean> mList;

    public ZhihuDailyAdapter(List<StoriesBean> list) {
        if (list == null) {
            mList = new ArrayList<>();
        } else {
            mList = list;
        }
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_zhihu_daily, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.ivDailyItemTitle.setText(mList.get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public void updateList(List<StoriesBean> stories) {
        mList.clear();
        mList.addAll(stories);
        notifyDataSetChanged();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_daily_item_image)
        ImageView ivDailyItemImage;
        @BindView(R.id.iv_daily_item_title)
        TextView ivDailyItemTitle;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
